import axios from 'axios';
export const getIpLocation = async () => {
    try {
        // 先尝试获取 IPv4
        const ipv4Response = await axios.get('https://api.ipify.org?format=json');
        const ipv4 = ipv4Response.data.ip;
        // 再获取位置信息
        const response = await axios.get(`https://ipapi.co/${ipv4}/json/`);
        const { city, region, country } = response.data;
        return {
            ip: ipv4,
            city: city || '',
            region: region || '',
            country: country || ''
        };
    }
    catch (error) {
        // 如果 IPv4 获取失败，回退到默认方式
        try {
            const response = await axios.get('https://ipapi.co/json/');
            const { ip, city, region, country } = response.data;
            return {
                ip: ip || 'Unknown IP',
                city: city || '',
                region: region || '',
                country: country || ''
            };
        }
        catch (fallbackError) {
            console.error('Failed to fetch IP location:', fallbackError);
            return null;
        }
    }
};
// # sourceMappingURL=ipLocation.js.map